import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {path:'/',redirect:'/login'}, //可以通过重定向设置默认跳转路由
    {path:'/manager', component: () => import('../views/Manager.vue'),children:[ //通过/manager/home来访问
    {path: 'home', name: 'home', meta:{title:'主页'},component: () => import('../views/Home.vue')},
    {path: 'test', name: 'test', meta:{title:'测试数据页'}, component: () => import('../views/Test.vue')},
    {path: 'data', name: 'data', meta:{title:'数据展示页'}, component: () => import('../views/Data.vue')},
    {path: 'employee', name: 'employee', meta:{title:'员工信息'}, component: () => import('../views/Employee.vue')},
    {path: 'admin', name: 'admin', meta:{title:'管理员信息'}, component: () => import('../views/Admin.vue')},
    {path: 'person', name: 'person', meta:{title:'个人信息'}, component: () => import('../views/Person.vue')}
  ]},
    {path: '/login', name: 'Login', meta:{title:'登录系统'}, component: () => import('../views/Login.vue')},
    {path: '/register', name: 'Register', meta:{title:'欢迎注册'}, component: () => import('../views/Register.vue')},
    {path: '/404', name: 'NotFound', meta:{title:'404找不到页面'}, component: () => import('../views/404.vue')},
    { path: '/:pathMatch(.*)', redirect: '/404' }
  ]
})

export default router

//beforeEach表示跳转前的一些操作
router.beforeEach((to,from,next)=>{
  document.title=to.meta.title
  next() //必须实现这个函数才能跳转
})
